#include "ttl.h"
#include "ui_ttl.h"


////test
#include <QUrl>
#include <QDebug>
#include <QFileDialog>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    //--- hot key ----
    if(ui->checkBox_1->checkState()) emit(beginHotkeys());
//    hotkeys = new QSystemHotkey;
//    connect(hotkeys, SIGNAL(runHotkey(int)),this,SLOT(hotkeyPressed(int)));
//    hotkeys->addKey(200,MOD_ALT,' ');
//    hotkeys->addKey(300,MOD_CONTROL,'X');
//    hotkeys->addKey(400,MOD_CONTROL,'Q');
//    QApplication::processEvents();
//    hotkeys->beginHotkeys();
//    // does not return!!!!!

    //--- TTS service ----
    tts= new GoogleTTS("en");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_1_clicked()
{
    tts->Speak(ui->textEdit->toPlainText());
}


void Widget::halt()
{
    hotkeys->haltHotkeys();
}

void Widget::hotkeyPressed(int position)
{
    switch (position) {
    case 200:
        qDebug() << "Case 200";
        break;
    case 300:
        qDebug() << "Case 300";
        break;
    case 400:
        qDebug() << "!!!Case 400: TURN OFF!!!";
        //halt();
        close();
        break;
    default:
        break;
    }
}

void Widget::on_checkBox_1_stateChanged(int arg1)
{
    if(arg1) emit(beginHotkeys());
    else emit(haltHotkeys());
}
